package com.liang.six_Direct_Exchanges;

import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import utils.RabbitmqUtil;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeoutException;

/**
 * Created with IntelliJ IDEA.
 * User: XIAOLIANG
 * Date: 2021/6/18
 * Time: 17:48
 * Description: direct 直接交换机 路由模式 / 根据routing key 将消息推入指定的队列
 */
public class DirectLogs {

    private static final String EXCHANGE_NAME = "direct_logs";

    public static void main(String[] args) throws IOException, TimeoutException {

        Channel channel = RabbitmqUtil.getChannel();

        channel.exchangeDeclare(EXCHANGE_NAME, BuiltinExchangeType.DIRECT);

        //创建 多个 binding key
        HashMap<String, String> hashMap = new HashMap<>();

        hashMap.put("info","普通的info信息");
        hashMap.put("waring","警告waring信息");

        for (Map.Entry<String, String> bindingEntry : hashMap.entrySet()) {
            channel.basicPublish(EXCHANGE_NAME,bindingEntry.getKey(),null,bindingEntry.getValue().getBytes("UTF-8"));
        }


    }

}